<template>
    <div class="tableContainer">
        <!-- <el-form :inline="true"  class="demo-form-inline">
            <el-form-item label="">
                <el-input class="elInput" v-model="key" placeholder="输入问题描述"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button class="elBtn" type="primary" @click="selectData()">查询</el-button>
            </el-form-item>
        </el-form> -->
        <el-table :data="tableData" max-height="88%" border style="width: 100%;overflow-y:auto;" >
            <el-table-column type="index" min-width="3%" align="center"></el-table-column>
            <el-table-column prop="comment" label="问题描述" min-width="20%" max-height="100px"  align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="images" label="问题图片" min-width="18%" max-height="100px"  align="center">
                <template slot-scope="scope">
                    <el-image  :src="item" v-for="(item,index) in scope.row.imagesList" :key="index" :preview-src-list="scope.row.imagesList" style="width: 30%;height:80%;margin-left:2%;"></el-image>
                </template>
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间"  min-width="15%" max-height="100px" align="center" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="contactWay" label="联系方式"  min-width="12%" max-height="100px" align="center" :show-overflow-tooltip="true" > </el-table-column>
            <el-table-column prop="op" label="操作" align="center" min-width="10%" max-height="100px">
                <template slot-scope="scope">
                    <el-button size="mini" icon="delete" type="danger" @click="openDialog(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background 
			layout="prev, pager, next, sizes, total, jumper"
			:page-sizes="pagesizes"
			:page-size="pagesize"
			:total="totalNum"
            @current-change="changePage"
            @size-change="sizeChange"
			>
		</el-pagination>

        <el-dialog title="提示" :visible.sync="centerDialogVisible" width="30%" center>
            <span>确定删除这条问题信息?</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button class="elBtn" type="primary" @click="doDelete">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
export default {
    data() {
        return {
            centerDialogVisible:false,// 问题删除对话框
            proId:"",// 问题id
            pagesizes:[1,15,20,25],
            pagesize:1,// 每页条数
            currpage: 1, // 当前页
            totalNum:0, // 总条数
            key: '',// 查询参数
            tableData: [], // 页面数据
            formLabelWidth: '30%', // label宽度
            clientHeight:"", // 屏幕高度
      }
    },
    created(){
        // 获取屏幕高度
        this.clientHeight = this.$common.getClientHeight()
        this.pagesize = Math.ceil((this.clientHeight - 265)/55)
        this.pagesizes[0] = this.pagesize

        // 数据初始化
        this.selectData()
    },
    
    methods:{
        openDialog(index,row){
            this.centerDialogVisible = true
            this.proId = row.id
        },
        // 初始化数据
        selectData(){
            const params = {
                key:this.key,
                page:this.currpage,
                limit:this.pagesize,
            }
            this.$api.selectProblem(params)
            .then(result => {
                var _this = this
                this.$common.filterLogin(result,_this,()=>{
                    if(result.data.success){
                         result.data.data.rows.forEach(el => {
                             if(el.images){
                                 el.imagesList = []
                                 
                                if(el.images.split(",")){
                                    el.imagesList = el.images.split(",")
                                }else{
                                    el.imagesList.push(el.images)
                                }
                             }
                             
                         })
                        _this.tableData = result.data.data.rows
                        _this.totalNum = result.data.data.totalRows
                        console.log(_this.tableData)
                    }else{
                        _this.$message({center: true,message: "加载失败，请稍后再试",type: 'warning'});
                    }
                    
                })
            })
        },
        doDelete(){
             this.$api.deleteProblem({params: {id: this.proId}}).then(result=>{
                var _this = this
                this.$common.filterLogin(result,_this,()=>{
                    _this.selectData()
                    if(result.data.success){
                        _this.centerDialogVisible = false
                        _this.$message({center: true,message:result.data.message?result.data.message:"操作成功",type: 'success'});
                    }else{
                        this.$message({center: true,message: result.data.message?result.data.message:"网络错误,请稍后再试",type: 'warning'});
                    }
                })
            })
        },
        // 分页--改变当前页
        changePage(index){
            this.currpage = index
            this.selectData()
        },
        // 分页--改变当前页显示条数
        sizeChange(page){
            this.pagesize = page
            this.selectData()
        }
    },
}
</script>

<style lang="scss" scoped>
.tableContainer{
    height: 96%;
    padding: 10px;
    background: #FDFDFD;
    border-radius: 5px;
    .el-pagination.is-background{
        text-align: right;
        padding:10px 5px;
    }
    .el-table,.el-table th, .el-table tr{
        background: transparent !important;
    }
}
</style>